import React, { PureComponent } from 'react'
import './index.scss';
import MainHeader from './components/MainHeader';
import Tuijian from './components/Tuijian'
import withRightNav1 from '../../components/hoc/withRightNav1';
import MiaoSha from './components/miaosha';
//引入 connect
import { connect } from 'react-redux';
//引入动作
import { fetchMainData } from '../../store/actions/wzdata';

class Main extends PureComponent {
    // constructor() {
    //     super();
    //     this.state = {
    //         tuijianList: [],
    //         swiperList: [],
    //         miaoshaObj: null
    //     }
    // }
    //钩子函数获取数据
    componentDidMount() {
        //调用 动作中的获取数据
        this.props.fetchMainData();
    }
    render() {
        let { tuijianList, swiperList, miaoshaObj, history } = this.props;
        return (
            <div className='main'>
                {
                    swiperList.length !== 0 ? <MainHeader swiperList={swiperList} history={history} /> : ""
                }
                {
                    miaoshaObj !== null ? <MiaoSha miaoshaObj={miaoshaObj} /> : ""
                }
                <Tuijian tuijianList={tuijianList} />
            </div>
        )
    }
}
export default connect(
    state => ({
        tuijianList: state.wzdata.tuijianList || [],
        swiperList: state.wzdata.swiperList || [],
        miaoshaObj: state.wzdata.miaoshaObj || null
    }), {
    fetchMainData
})(withRightNav1(Main));
